GdPicture.NET.14.API
GdPicture14 Namespace / GdPictureImaging Class / CreateGdPictureImageFromByteArray Method / CreateGdPictureImageFromByteArray(Byte[],DocumentFormat) Method
The image data stored in the array of bytes. This object must be initialized with the proper image data and it must be disposed of by the user as well.
A member of the DocumentFormat enumeration. Specifies an image file format.
Example





In This Topic
CreateGdPictureImageFromByteArray(Byte[],DocumentFormat) Method
In This Topic
Creates a new GdPicture image from an image file stored as an array of bytes. You can specify the image format using this method. The newly created image is identified by its unique non-zero image identifier.

Please note that it is your responsibility to release the image resources once you have no use for them.

Syntax
'Declaration
 
Public Overloads Function CreateGdPictureImageFromByteArray( _
   ByVal Data() As Byte, _
   ByVal ImageFormat As DocumentFormat _
) As Integer
public int CreateGdPictureImageFromByteArray( 
   byte[] Data,
   DocumentFormat ImageFormat
)
public function CreateGdPictureImageFromByteArray( 
    Data: Bytearray of;
    ImageFormat: DocumentFormat
): Integer; 
public function CreateGdPictureImageFromByteArray( 
   Data : byte[],
   ImageFormat : DocumentFormat
) : int;
public: int CreateGdPictureImageFromByteArray( 
   byte[]* Data,
   DocumentFormat ImageFormat
) 
public:
int CreateGdPictureImageFromByteArray( 
   array<byte>^ Data,
   DocumentFormat ImageFormat
) 

Parameters

Data
The image data stored in the array of bytes. This object must be initialized with the proper image data and it must be disposed of by the user as well.
ImageFormat
A member of the DocumentFormat enumeration. Specifies an image file format.

Return Value

A unique image identifier of the GdPicture image representing the newly created image. The returned value is non-zero if the image is successfully created. Please first of all use the GdPictureImaging.GetStat method to determine if this method has been successful.

Be aware that you need to release the image with the GdPictureImaging.ReleaseGdPictureImage method after being used.

Remarks
It is recommend to use the GdPictureImaging.GetStat method to identify the specific reason for the method's failure, if any.

All document formats currently supported by the toolkit are listed here.

This class loads multipage images (GIF and TIFF formats) in read-write mode by default. If you want to open multipage images in read-only mode, you need to call the GdPictureImaging.GifOpenMultiFrameForWrite method for GIF format and the GdPictureImaging.TiffOpenMultiPageForWrite method for TIFF format and set the WriteAccess parameter to false before creating an image.

This method requires the Image Documents component to run.

Example
Creating a GdPicture image from an image file stored as an array of bytes and saving to a PNG file.
using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
using (Stream stream = File.Open("image.jpg", FileMode.Open))
{
    // Load the file to an array of bytes for the sake of demonstration.
    // In a production context, the image file should be obviously loaded with CreateGdPictureImageFromFile.
    int size = (int)stream.Seek(0, SeekOrigin.End);
    byte[] buffer = new byte[size];
    stream.Seek(0, SeekOrigin.Begin);
    stream.Read(buffer, 0, size);
 
    // Create the GdPicture image and save it as a PNG.
    int imageID = gdpictureImaging.CreateGdPictureImageFromByteArray(buffer, GdPicture14.DocumentFormat.DocumentFormatJPEG);
    gdpictureImaging.SaveAsPNG(imageID, "image.png");
    gdpictureImaging.ReleaseGdPictureImage(imageID);
}
See Also